<template>
  <div class="login-setting">
    <el-form ref="form" :model="userInfo" label-width="215px" :rules="rules">
      <el-form-item label="姓名：" prop="username">
        <el-input v-model="userInfo.username" class="inputW" />
      </el-form-item>
      <el-form-item label="密码：" prop="password">
        <el-input v-model="userInfo.password" class="inputW" type="password" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="saveFn">更新</el-button>
        <el-button @click="$router.back()">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { saveUserDetailById } from '@/api/employees'
import { getUserDetailById } from '@/api/user'
export default {
  name: 'LoginSetting',

  data() {
    return {
      userInfo: {},
      rules: {
        username: [{ required: true, message: '用户名不能为空', triggler: 'blur' }],
        password: [{ required: true, message: '密码不能为空', triggler: 'blur' }]
      }
    }
  },
  // 因为赋值在异步任务后所以，我们使用监听，在赋值完成后再对form进行赋值
  created() {
    this.getUserDetailFn()
  },
  methods: {
    async saveFn() {
      console.log(this.$route.query.emoloyeeId)
      const res = await saveUserDetailById(this.userInfo)
      this.$message.success(res.message)
    },
    // 获取个人信息
    async getUserDetailFn() {
      const res = await getUserDetailById(this.$route.query.emoloyeeId)
      console.log(res)
      this.userInfo = res.data
    }
  }

}
</script>

<style lang="scss" scoped>
.login-setting {
  padding: 30px;
}
::v-deep .el-input__inner {
  height: 36px;
  line-height: 36px;
}
.el-form {
  margin-left: 130px;
}
.inputW {
  width: 300px;
}
</style>
